<?php

namespace app\admin\controller\api;

use think\admin\Controller;
use think\admin\service\AdminService;

/**
 * 通用插件管理
 * Class Plugs
 * @package app\admin\controller\api
 */
class Plugs extends Controller
{

    /**
     * 图标选择器
     * @login true
     */
    public function icon()
    {
        $this->title = '图标选择器';
        $this->field = $this->app->request->get('field', 'icon');
        $this->fetch(realpath(__DIR__ . '/../../view/api/icon.html'));
    }

    /**
     * 优化数据库
     * @login true
     */
    public function optimize()
    {
        if (AdminService::instance()->isSuper()) {
            sysoplog('系统运维管理', '创建数据库优化任务');
            $this->_queue('优化数据库所有数据表', 'xadmin:database optimize');
        } else {
            $this->error('只有超级管理员才能操作！');
        }
    }

    /**
     * 地图选择器
     * @login true
     */
    public function mapselector()
    {
        $this->title = '地图选择器';
        $get = $this->request->get();
        $lat = isset($get['lat']) && !empty($get['lat']) ?$get['lat']:'31.23958';
        $long = isset($get['long']) && !empty($get['long']) ?$get['long']:'121.49976';
        $address = isset($get['address']) && !empty($get['address']) ?$get['address']:'';
        $this->fetch(realpath(__DIR__ . '/../../view/api/mapselector.html'), ['lat' => $lat, 'long' => $long, 'address' => $address]);
    }
}